#ifndef FILEPARSER_H
#define FILEPARSER_H

#include <QtCore>
#include <QImage>
#include <stdexcept>

#include "triangle.h"
#include "couple.h"
#include "Vector3D.h"
#include "renderpseudothread.h"

using namespace std;

class fileParser
{
public:
    //exceptions
    class FileNotOpenEx : public runtime_error {
    public:
        FileNotOpenEx(const string& msg = "") : runtime_error(msg) {};
    };
    class BadFileStructureEx : public runtime_error {
    public:
        BadFileStructureEx(const string& msg = "") : runtime_error(msg) {};
    };

    //meber functions
    fileParser();
    void parse(QString fileName);
    void populate(RenderPseudoThread* thread);
    void draw(QImage* image,const QMatrix& matrix, RenderPseudoThread* thread,
              bool grid, bool showVertexNames, bool showTriangleNames, bool showContours);
    enum Mode {ENone, EGridOnly, EScalar0, EVector0, EScalar1, EVector1};
    friend class Field;
private:
    QVector<QPointF> vertices;
    QVector<triangle*> triangles;
    QVector<float> triangleHeight;
    QMap<int,QPointF> triangleVector;
    QMap<int,QPointF> nodeVector;
    QVector<float> vertexHeight;
    float min;
    float max;
    Mode currentMode;

    bool loadVector(QTextStream& t, int expectedCount, QMap<int,QPointF>& vectorMap);
    bool parseOctaveDesc(QTextStream& t, QString& name, QString& type, int& rows, int& columns);
public:
    float getMin(){return min;}
    float getMax(){return max;}
    Mode mode() {return currentMode;}

};

#endif // FILEPARSER_H
